﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace taskAtachmentsChilds
{
    class Program
    {
        public static void Main()

        {

            Task<Int32[]> parent = Task.Run(() =>

            {
                var results = new Int32[3];

                new Task(() => results[0] = 0, 

                    TaskCreationOptions.AttachedToParent).Start();
                Thread.Sleep(1000);

                new Task(() => results[1] = 1, 

                    TaskCreationOptions.AttachedToParent).Start();
                Thread.Sleep(1000);
                new Task(() => results[2] = 2, 

                    TaskCreationOptions.AttachedToParent).Start();
                Thread.Sleep(1000);
                return results;

            });

            var finalTask = parent.ContinueWith(

               parentTask => {

                   foreach(int i in parentTask.Result)

                    Console.WriteLine(i);

               });
            finalTask.Wait();

            Console.Read();

        }
    }
}
